package com.liaoban.app.ui.base;

import android.os.Bundle;

import com.liaoban.app.helper.ToastHelper;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;

import java.util.Map;

/**
 * 第三方授权
 */
public abstract class BaseLoginActivity extends BaseActivity {

    @Override
    protected void onDestroy() {
        super.onDestroy();
        UMShareAPI.get(this).release();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        UMShareAPI.get(this).onSaveInstanceState(outState);
    }

    public void doOauthVerify(SHARE_MEDIA var2) {
        UMShareAPI.get(this).doOauthVerify(this, var2, authListener);
    }

    UMAuthListener authListener = new UMAuthListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
            showRunningDialog();
        }

        @Override
        public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
            dismissRunningDialog();
            ToastHelper.show(BaseLoginActivity.this, "成功了");
            String openid = data.get("openid");
            doOauthVerifySuc(openid);
            /*Log.e("yubch", "openid:" + data.get("uid") + ",unionid:" + data.get("unionid"));
            Log.e("yubch", "name:" + data.get("name") + ",screen_name:" + data.get("screen_name"));
            Log.e("yubch", "iconurl:" + data.get("iconurl") + ",profile_image_url:" + data.get("profile_image_url"));
            Log.e("yubch", "size:" + data.size());
            for (String key : data.keySet()) {
                Log.e("yubch", "key:" + key + ", value:" + data.get(key));
            }*/
        }

        @Override
        public void onError(SHARE_MEDIA platform, int action, Throwable t) {
            dismissRunningDialog();
            ToastHelper.show(BaseLoginActivity.this, "授权失败");
        }

        @Override
        public void onCancel(SHARE_MEDIA platform, int action) {
            dismissRunningDialog();
            ToastHelper.show(BaseLoginActivity.this, "授权取消");
        }
    };

    public abstract void doOauthVerifySuc(String openid);
}
